﻿using System;
using System.Collections.Generic;
using Google.Analytics.Model;
using Google.Analytics.Model.Feeds;
using Google.Analytics.Model.Queries;
using Google.Analytics.RemoteAccess.API;
using NUnit.Framework;

namespace Google.Analytics.RemoteAccessTests
{
    [TestFixture]
    public class GoogleAPITests : RemoteAccessTestsBase
    {
        [Test]
        public void GetAccounts()
        {
            var api = new AnalyticsAPI(State);
            var query = new AccountQuery(State);
            AccountFeed feed = api.GetAccounts(query);

            Assert.IsNotNull(feed, "Returned null feed");
            Assert.AreNotEqual(0, feed.TotalResults);
            Assert.Greater(feed.Entries.Count, 0, "Zero number of entries");

            foreach (var c in feed.Entries)
            {
                var entry = (AccountEntry) c;
                
                Assert.IsNotNull(entry.AccountName, "Account name is null");
                Assert.IsNotNull(entry.AccountID, "Account id is null");
                Assert.IsNotNull(entry.WebPropertyId, "WebPropertyId id is null");
                Assert.IsNotNull(entry.Currency, "Currency id is null");
                Assert.IsNotNull(entry.Timezone, "Timezone id is null");
            }
        }

        [Test]
        public void GetData()
        {
            var api = new AnalyticsAPI(State);
            var query = new DataQuery(State, id, DateTime.Now.AddDays(-15), DateTime.Now, new List<Metrics> { Metrics.Visits}, new List<Dimensions> {Dimensions.Week}, new Order[0], "");
            DataFeed feed = api.GetData(query);
        }
    }
}
